怎么用c++编成求解b^2-4ac<0的方程?

来源:百度知道 编辑:UC知道 时间:2024/06/01 12:08:09
怎么球?
怎么输出他的两个根??
记得以前在那儿看过,现在忘了。请各位高手帮帮忙。

#include <iostream>
#include <math.h>
using namespace std;
float x1,x2,disc,p,q;
int main()
{void greater_than_zero(float,float);
void equal_to_zero(float,float);
void smaller_than_zero(float,float);
float a,b,c;
cout<<"input a,b,c:";
cin>>a>>b>>c;
disc=b*b-4*a*c;
cout<<"root:"<<endl;
if (disc>0)
{
greater_than_zero(a,b);
cout<<"x1="<<x1<<",x2="<<x2<<endl;
}
else if (disc==0)
{equal_to_zero(a,b);
cout<<"x1="<<x1<<",x2="<<x2<<endl;
}
else
{smaller_than_zero(a,b);
cout<<"x1="<<p<<"+"<<q<<"i"<<endl;
cout<<"x2="<<p<<"-"<<q<<"i"<<e